<?php
/**
 * Created by PhpStorm.
 * User: HLG
 * Date: 2018/12/8
 * Time: 17:30
 */
namespace app\shop\controller;

use app\shop\model\GoodsModel;
use think\Session;
/*
 * 商品管理类
 * */
class Goods extends BaseController
{
    protected $goodsModel;
    protected $goodsGroupModel;
    public function __construct()
    {
        parent::__construct();
        $this->goodsModel = new GoodsModel();
    }
    //商品列表
    public function index()
    {
        $shop = Session::get('shop');
        $goodsList = $this->goodsModel->getGoodsList();
        $this->assign('page',$goodsList->render());
        $this->assign('goodsList',$goodsList);
        $this->assign('shop',$shop);
        return view('goods/index');
    }
    //商品编辑
    public function goodsEdit()
    {
        if(input('post.')){
            $goodsInfo = $this->goodsModel->goodsEdit();
            return $goodsInfo;
        }else{
            $goodsInfo = $this->goodsModel->goodsEdit();
            $this->assign('goodsInfo',$goodsInfo);
            return view('goods/edit');
        }
    }
    //商品添加
    public function goodsAdd()
    {
        if(input('post.')){
            $result = $this->goodsModel->goodsAdd();
            return $result;
        }else{
            $goodsInfo = $this->goodsModel->goodsAdd();
            $this->assign('goodsInfo',$goodsInfo);
            return view('goods/edit');
        }
    }
    //商品删除
    public function goodsDel()
    {
        $result = $this->goodsModel->goodsDel();
        return $result;
    }
    //查看商品简介
    public function lookSynopsis()
    {
        $info = $this->goodsModel->lookSynopsis();
        $this->assign('info',$info);
        return view('goods/synopsis');
    }
    //查看商品图
    public function lookImg()
    {
        $info = $this->goodsModel->lookImg();
        $this->assign('info',$info);
        return view('goods/synopsis');
    }
    //编辑状态
    public function updateStatus()
    {
        $result = $this->goodsModel->updateStatus();
        return $result;
    }
  //上传图片
    public function uploadImg()
    {
        $res = $this->goodsModel->uploadImg();
        return $res;
    }
    //删除图片
    public function delImg()
    {
        $res = $this->goodsModel->delImg();
        return $res;
    }
    //删除图片
    public function delImgs()
    {
        $res = $this->goodsModel->delImgs();
        return $res;
    }
}